<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Slidetype_Flickr
 * @category   Slide Type
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slidetype_Announcement extends Bbce_Slidetype_Abstract
{   
    /**
     * Title of the plugin, as shown in the interface
     * 
     * @var string
     */
    protected $_title = 'Announcement';
    
    /**
     * Description of the plugin, as shown in the interface
     * 
     * @var string
     */
    protected $_description = 'Create a slide with an image and corresponding text';
    
    /**
     * Builds the slide requested.  Returns an associative
     * array of key => value pairs of variables to be assigned
     * to the view object.
     * 
     * Example:  return array('url' => 'http://www.google.com');
     * 
     * This will assign the value of "http://www.google.com" to the view
     * variable "url".  In the view, you will access this by "echo $this->url";
     * 
     * @param int $slideId
     * @return array
     */
    public function buildSlide($slideId)
    {
        $thisSlide = $this->find($slideId);

        $config = Zend_Registry::get('config');
      
        return array(
        	'article'	 => $thisSlide['article'],
        	'imageURL'	 => $thisSlide['imageURL'],
            'bgColor'    => $thisSlide['bgColor'],
        	'textColor'	 => $thisSlide['textColor'],
        	'bgImageURL' => $thisSlide['bgImage'],
        	'imgPos'	 => $thisSlide['imagePos'],
        	'border'	 => $thisSlide['border'],
        	'midBorder'	 => $thisSlide['midBorder'],
        	'borderClr'	 => $thisSlide['borderColor'],
        	'contentPos' => $thisSlide['imagePos'] == 'left' ? 'right' : 'left',
        	'fontFamily' => $thisSlide['fontFamily']
        );
    }
    
    /**
     * Generates a thumbnail for the given slide.
     * 
     * @param $slideId
     * @return PHPGD image object
     */
    public function generateSlideThumbnail($slideId)
    {
        $path = realpath(APPLICATION_PATH . '/../loadable/slidetype/Announcement/thumbnail.jpg');

        return imagecreatefromjpeg($path);
    }       
    
    /**
     * Generates a Zend_Form object which is displayed when
     * editing the given slide type.  The $values array is
     * a key => value associative array that maps the form
     * field names with their default values, if any.
     * 
     * @param array $values
     * @return object Zend_Form
     */
    public function getConfigurationForm($values = array())
    {
        $form = new Zend_Form();
        $form->setAttrib('class', 'slideTypeForm')
             ->setDecorators(array(
                     'FormElements',
                     array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')),
                     'Form'
             ));
        
        $text = $form->createElement('textarea', 'article', array('label' => 'Text:'));
        $text->setAttrib('cols', 52)
             ->setAttrib('rows', 13)
             ->setAttrib('style', 'width: 375px; height: 200px;')
             ->setAttrib('class', 'richtext')
             ->setValue(isset($values['article']) ? $values['text']  : '');
        
        
        $image = $form->createElement('text', 'imageURL', array('label' => 'Image Url:'));
        $image->setValue(isset($values['imageURL']) ? $values['imageURL'] : '');
        
        $imagePos = $form->createElement('select', 'imagePos', array('label' => 'Image Position:'));
		$imagePos->setMultiOptions(array(
			'left' => 'Left',
			'right' => 'Right',
		));        
        
        $bgImage = $form->createElement('text', 'bgImage', array('label' => 'Background Image: (optional)'));
        $bgImage->setValue(isset($values['bgImageURL']) ? $values['bgImageURL'] : '');
        
        $bgAlignmentValues = array(
                                'topLeft'      => 'Top Left',
                                'topCenter'    => 'Top Center',
                                'topRight'     => 'Top Right',
                                'centerLeft'   => 'Center Left',
                                'centerCenter' => 'Center Center',
                                'centerRight'  => 'Center Right',
                                'bottomLeft'   => 'Bottom Left',
                                'bottomCenter' => 'Bottom Center',
                                'bottomRight'  => 'Bottom Right'
                            );
        
        $bgAlignment = $form->createElement('select', 'bgAlignment', array('label' => 'Background Alignment:'));
        $bgAlignment->setMultiOptions($bgAlignmentValues)
                    ->setValue(isset($values['bgAlignment']) ? $values['bgAlignment'] : 'topLeft');
       
                    
        $bgRepeatValues = array(
                                'no-repeat' => 'No Repeat',
                                'repeat'    => 'Repeat Vertically & Horizontally',
                                'repeat-y'  => 'Repeat Vertically',
                                'repeat-x'  => 'Repeat Horizontally'
                            );
        
        $bgRepeat = $form->createElement('select', 'bgRepeat', array('label' => 'Background Repeat:'));
        $bgRepeat->setMultiOptions($bgRepeatValues)
                 ->setValue(isset($values['bgRepeat']) ? $values['bgRepeat'] : 'no-repeat');
                    
                    
        $bgColor = $form->createElement('text', 'bgColor', array('label' => 'Background Color:'));
        $bgColor->setAttrib('size', 6)
                ->setAttrib('maxlength', 6)
                ->setAttrib('class', 'color');

        $bgColor->setValue(isset($values['bgColor']) ? $values['bgColor'] : 'FFFFFF');

        $txtColor = $form->createElement('text', 'textColor', array('label' => 'Text Color:'));
        $txtColor->setAttrib('size', 6)
                ->setAttrib('maxlength', 6)
                ->setAttrib('class', 'color');

        $txtColor->setValue(isset($values['textColor']) ? $values['textColor'] : '000000');
        
        $fontFamily = $form->createElement('select', 'fontFamily', array('label' => 'Font:'));
        $fontFamily->setMultiOptions(array(
                  'Arial'                   => 'Arial',
                  'Cantarell'               => 'Cantarell',
                  'Cardo'                   => 'Cardo',
                  'Courier'                 => 'Courier',
                  'Crimson Text'            => 'Crimson Text',
                  'Cuprum'                  => 'Cuprum',
                  'Droid Sans'              => 'Droid Sans',
                  'Droid Serif'             => 'Droid Serif',
                  'Helvetica'               => 'Helvetica',
                  'IM Fell'                 => 'IM Fell',
                  'Inconsolata'             => 'Inconsolata',
                  'Josefin Sans Std Light'  => 'Josefin Sans Std Light',
                  'Lobster'                 => 'Lobster',
                  'Molengo'                 => 'Molengo',
                  'Neucha'                  => 'Neucha',
                  'Neuton'                  => 'Neuton',
                  'Nobile'                  => 'Nobile',
                  'OFL Sorts Mill Goudy TT' => 'OFL Sorts Mill Goudy TT',
                  'Old Standard TT'         => 'Old Standard TT',
                  'PT Sans'                 => 'PT Sans',
                  'Philosopher'             => 'Philosopher',
                  'Reenie Beanie'           => 'Reenie Beanie',
                  'Tangerine'               => 'Tangerine',
                  'Verdana'                 => 'Verdana',
                  'Vollkorn'                => 'Vollkorn',
                  'Yanone Kaffeesatz'       => 'Yanone Kaffeesatz'
                ))
                ->setDescription('See http://code.google.com/webfonts for more information')
                ->setValue(isset($values['fontFamily']) ? $values['fontFamily'] : 'Arial');
        
        $border = $form->createElement('select', 'border', array('label' => 'Border type:'));
        $border->setMultiOptions(array(
        	'rounded' => 'Rounded Border',
        	'square'  => 'Square Border',
        	'none'    => 'None',
        ));
        
        $separatingBorder = $form->createElement('select', 'midBorder', array('label' => 'Separating border:'));
        $separatingBorder->setMultiOptions(array(
        	1 => 'Yes',
        	0 => 'No',
        ));

        $borderColor = $form->createElement('text', 'borderColor', array('label' => 'Border Color:'));
        $borderColor->setAttrib('size', 6)
                ->setAttrib('maxlength', 6)
                ->setAttrib('class', 'color');

        $borderColor->setValue(isset($values['borderColor']) ? $values['borderColor'] : '000000');
        
        
        
        $form->addElements(array($image, $text, $txtColor, $fontFamily, $bgImage, $bgAlignment, $bgRepeat, $bgColor, $imagePos, $border, $separatingBorder, $borderColor));

        $form->setElementDecorators(array(
                  'ViewHelper',
                  'Errors',
                  array('HtmlTag', array('tag' => 'div', 'class' => 'elm')),
                  array('Label', array('tag' => 'span')),
                  array('Description', array('tag' => 'div', 'class' => 'elmDescription'))
              ));
        
        return $form;   
    }
}